// webUtils.js
const fs = require('fs');
const axios = require('axios');
async function downloadFile(url, filePath) {
    try {
        const response = await axios({
            url: url,
            method: 'GET',
            responseType: 'stream'
        });

        const writer = fs.createWriteStream(filePath);

        response.data.pipe(writer);

        return new Promise((resolve, reject) => {
            writer.on('finish', resolve);
            writer.on('error', reject);
        });
    } catch (err) {
        console.error('下载出错:', err);
        throw err;
    }
}

module.exports = { downloadFile };
